module MC {
    class _OS {
        public constructor() {
            let ua = navigator.userAgent;
            ua = ua.toLowerCase();
            //	debug.log(ua);
            /*	if (ua.indexOf('miuibrowser') > 0) {
                    this.miuibrowser = true;
                }*/
            if (ua.indexOf('iphone') > 0) {
                this.iphone = true;
            }
            if (ua.indexOf('android') > 0) {
                this.android = true;
            }
            if (ua.indexOf('micromessenger') > 0) {
                this.MicroMessenger = true;
            }
            if (ua.indexOf('qq') > 0 && this.MicroMessenger === false) {
                this.phoneQQ = true;
            }
            this.iphoneX = /iphone/gi.test(navigator.userAgent) && (screen.height == 812 && screen.width == 375);
            if (ua.indexOf('iphone x') > 0) {
                this.iphoneX = true;
            }
            if (ua.indexOf('neteasemusic') > 0) {
                this.musicApp = true;
            }
            if (ua.indexOf('qqreader') > 0) {
                this.qqreader = true;
            }
        }

        public init() {
            if (this.iphoneX) {
                $('body').addClass("iphoneX");
            }
            /*
            $(window).resize(() => {
                this.sizeBody();
            });
            this.sizeBody();
            */
        }

        public initSizeBody() {
            $(window).resize(() => {
                this.sizeBody();
            });
            this.sizeBody();
        }

        public qqreader = false;
        /*** 判断是否为小米浏览器 */
        public miuibrowser = false;
        /** 判断是否为iPhone X */
        public iphoneX = false;
        /** 是否为Android环境 */
        public android: boolean = false;
        /** 是否为iphone环境 */
        public iphone: boolean = false;
        /** 是否为MicroMessenger */
        public MicroMessenger: boolean = false;
        /** 是否为手机QQ环境 */
        public phoneQQ = false;
        public musicApp = false;

        /**
         * 获取是否为横屏模式
         */
        get ishorizontal(): boolean {

            if ($(window).width() > $(window).height()) {
                return true;
            } else {
                return false;
            }
        }

        /** 获取当前旋转以后的宽高 */
        get hor_width(): number {
            if (this.ishorizontal) {
                return $(window).height();
            } else {
                return $(window).width();
            }
        }

        /** 获取当前旋转以后的宽高 */
        get hor_height(): number {
            if (!this.ishorizontal) {
                return $(window).height();
            } else {
                return $(window).width();
            }
        }

        /** 判断是否为沉浸 */
        get IsImmerse() {
            return false;
            //	return location.href.indexOf('_wv=16777218')>0;
        }

        /** 获取get参数 */
        public query(n: string) {
            var m = window.location.search.match(new RegExp("(\\?|&)" + n + "=([^&]*)(&|$)"));
            return !m ? "" : decodeURIComponent(m[2]);
        }

        private sizeBody() {
            let w = $(window).width();
            let _W = 750;

            var scale = w / _W;
            // console.log("scale="+scale);
            $('html').css('font-size', scale * 100 + 'px');
        }

        public loadJsUrl(src: string, func: Function = null) {
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.src = src;
            var head = document.getElementsByTagName('head').item(0);
            head.appendChild(script);

            script.onload = function () {
                func && func();
            };
        };

        public loadCssUrl(src: string) {
            var script = document.createElement('link');
            script.type = 'text/css';
            script.rel = 'stylesheet';
            script.href = src;
            var head = document.getElementsByTagName('head').item(0);
            head.appendChild(script);

        }

        public GetRequest(urlStr:string='') {
            if (typeof urlStr == "undefined"||urlStr=='') {
                var url = decodeURI(location.search); //获取url中"?"符后的字符串
            } else {
                var url = "?" + urlStr.split("?")[1];
            }
            let strs;
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
                }
            }
            return theRequest;

        }
    }

    /** 定义缩放模式 */
    export enum zoom {
        /**
         * 自动宽高，宽高占满
         * */
        auto, ///: 'VIDEO.setShowType.auto', ////
        /**
         * 宽度占满,高度自动
         */
        Width_topauto,
        /**
         * 宽度占满,高度为0
         */
        Width,
        /**
         * 高度占满  宽度自动居中
         */
        Height,
        /** 适应  保证视频不变形,并且全部显示出来 */
        shiying,
        /** 底部对齐 */
        bottom
    };
    export let OS = new _OS;

    $(() => {
        OS.init();
    });


}